package cn.ibizlab.todo.core.pms.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.todo.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.todo.core.pms.domain.Project;
import cn.ibizlab.todo.core.pms.filter.ProjectSearchContext;
import cn.ibizlab.todo.core.pms.service.IProjectService;

import cn.ibizlab.todo.util.helper.CachedBeanCopier;
import cn.ibizlab.todo.util.helper.DEFieldCacheMap;


import cn.ibizlab.todo.core.pms.client.ProjectFeignClient;

/**
 * 实体[项目] 服务对象接口实现
 */
@Slf4j
@Service
public class ProjectServiceImpl implements IProjectService {

    @Autowired
    ProjectFeignClient projectFeignClient;


    @Override
    public boolean create(Project et) {
        Project rt = projectFeignClient.create(et);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;
    }

    public void createBatch(List<Project> list){
        projectFeignClient.createBatch(list) ;
    }

    @Override
    public boolean update(Project et) {
        Project rt = projectFeignClient.update(et.getId(),et);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;

    }

    public void updateBatch(List<Project> list){
        projectFeignClient.updateBatch(list) ;
    }

    @Override
    public boolean remove(Long id) {
        boolean result=projectFeignClient.remove(id) ;
        return result;
    }

    public void removeBatch(Collection<Long> idList){
        projectFeignClient.removeBatch(idList);
    }

    @Override
    public Project get(Long id) {
		Project et=projectFeignClient.get(id);
        if(et==null){
            et=new Project();
            et.setId(id);
        }
        else{
        }
        return  et;
    }

    @Override
    public Project getDraft(Project et) {
        et=projectFeignClient.getDraft();
        return et;
    }

    @Override
    public boolean checkKey(Project et) {
        return projectFeignClient.checkKey(et);
    }
    @Override
    @Transactional
    public Project favorites(Project et) {
        //自定义代码
        return et;
    }

    @Override
    @Transactional
    public boolean save(Project et) {
        if(et.getId()==null) et.setId((Long)et.getDefaultKey(true));
        if(!projectFeignClient.save(et))
            return false;
        return true;
    }

    @Override
    public void saveBatch(List<Project> list) {
        projectFeignClient.saveBatch(list) ;
    }

    @Override
    @Transactional
    public Project saveProject(Project et) {
        //自定义代码
        return et;
    }

    @Override
    @Transactional
    public Project saveProjectTeam(Project et) {
        //自定义代码
        return et;
    }





    /**
     * 查询集合 当前用户项目
     */
    @Override
    public Page<Project> searchCurUser(ProjectSearchContext context) {
        Page<Project> projects=projectFeignClient.searchCurUser(context);
        return projects;
    }

    /**
     * 查询集合 数据集
     */
    @Override
    public Page<Project> searchDefault(ProjectSearchContext context) {
        Page<Project> projects=projectFeignClient.searchDefault(context);
        return projects;
    }




}



